package org.maylove.wuziqi.dao;

import org.maylove.wuziqi.pojo.user.User;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface UserDao extends JpaRepository<User, Integer> {

    @Query(value = "SELECT u FROM User u WHERE u.username = ?1")
    User findByUsername(String username);

    @Query(value = "SELECT u FROM User u WHERE u.userId = ?1")
    User findByUserId(Long userId);

    @Query(nativeQuery = true, value = "SELECT * FROM user ORDER BY identity DESC, username ASC LIMIT ?,?")
    List<User> getUser(int start, int pageSize);
}
